<template>
    <div class="Information">
        <div class="Information_main cursor_pointer" v-if="personData" @click="detail()">
            <div v-if="status >-1" class="Information_main">
                <div class="Information_main_ ">
                <p class="Information_main_title fontz fontw700 fonts24 ">{{ personData.positionName }}</p>
                <p class="Information_main_p fontz fonts18">
                    <span class="colorRed ">{{ personData.salaryStart }}-{{ personData.salaryEnd }}{{ personData.salaryUnit
                    }}
                        {{ personData.salaryRange }}薪</span>
                    <span class="gray" v-if="personData.requirementsYears">| {{ dict(personData.requirementsYears,
                        "requirements_years") }}</span>
                    <span class="gray" v-if="personData.educationRequirements">| {{ dict(personData.educationRequirements,
                        "education") }}</span>
                    <span class="gray" v-if="personData.applicationAddress">| {{ personData.applicationAddress }}</span>
                </p>
                <div class="flex" style="margin-top: 16px;" v-if="string_arrFun(personData.welfareTreatment).length != 0">
                    <p class="Information_main_left_btn fontz" v-for="item in string_arrFun(personData.welfareTreatment)">
                        {{ dict(item, 'welfare_treatment') }}</p>
                </div>
            </div>
            <div class="Information_main_" style=""
                v-if="personData.tenantVo.companyName || personData.tenantVo.companyType || personData.tenantVo.companySize || personData.tenantVo.companyIndustry">
                <p class=" fontz gray fonts20">{{ personData.tenantVo.companyName }}</p>
                <p class=" fontz gray fonts20">行业：{{ dict(personData.tenantVo.companyType, "company_type") }}</p>
                <p class=" fontz gray fonts20">性质：{{ dict(personData.tenantVo.companyIndustry, "company_industry") }} |
                    {{ dict(personData.tenantVo.companySize, "company_size") }}</p>
            </div>
            </div>
            <div v-else></div>
            <div class="Information_main_ Information_main_flex_end">
                <div class="flex" v-if="status == '-1'">
                    <div class="fonts16" style="color: #fe6470;" >该职位已删除</div>
                </div>
                <div class="flex" v-if="status == '0'">
                    <div class="fonts16" style="color: #fe6470;" >该职位已关闭</div>
                </div>
                <div class="flex" v-if="status != '-1' && status != '0'">
                    <!-- <el-button class="flex aic" type="primary" style="margin-bottom: 16px;"
                        v-if="indexValue == 0 || indexValue == 1 || index == 0" @click="toudi()">投递简历
                    </el-button> -->
                    <!-- <el-button class="flex aic" type="primary" style="margin-bottom: 16px;" v-if="index == 1">已投递
                    </el-button> -->
                    <!-- 投递简历 -->
                    <div v-if="index < 1">
                        <div class="flex">
                            <el-button class="blue_btn" type="primary" @click="toudi()">投递简历
                            </el-button>
                            <el-button type="primary" icon="el-icon-star-off" class="flex aic" @click="collectionApi"
                                v-if="personData.isCollection == 0 && indexValue != 1">收藏</el-button>
                            <el-button type="primary" icon="el-icon-star-on" class="flex aic" @click="collectionApi"
                                v-if="personData.isCollection != 0 && indexValue != 1">取消收藏</el-button>
                        </div>
                    </div>
                    <!-- 已投递 -->
                    <div v-if="index == 1">
                        <el-button class="blue_btn" type="primary">已投递
                        </el-button>
                        <div class="Information_main_time_gray">
                            <span class="fontz">投递时间：{{ personData.createTime }}</span>
                        </div>
                    </div>
                    <!-- 已通知笔试-->
                    <div v-if="index == 2">
                        <div class="flex">
                            <el-button type="danger" @click="getup()">放弃笔试</el-button>
                            <el-button class="blue_btn" type="primary" v-if="index == 2" @click="request()">确认参加
                            </el-button>
                        </div>
                        <div class="Information_main_time_gray">
                            <span class="fontz">通知时间：{{ personDatas.createTime }}</span>
                        </div>
                    </div>
                    <!-- 已放弃笔试 -->
                    <div class="fonts16" style="color: #fe6470;" v-if="index == 4"> 已放弃笔试</div>
                    <!-- 已确认参加笔试 -->
                    <div v-if="index == 5">
                        <div class="Information_main_time_gray">
                            <span class="fontz fonts16" style="color: #2f6cbc;">已确认参加笔试</span>
                        </div>
                        <div class="Information_main_time_gray">
                            <span class="fontz">笔试时间：{{ personDatas.writingTestingTime || "暂无" }}</span>
                        </div>
                    </div>
                    <!-- 笔试未通过 -->
                    <div class="fonts16" style="color: #fe6470;" v-if="index == 6"> 笔试未通过</div>
                    <!-- 笔试7通过 -->
                    <div class="fonts16" style="color: #2f6cbc;" v-if="index == 7">笔试通过</div>
                    <!-- 面试 -->
                    <div v-if="index == 8">
                        <div class="Information_main_time_gray">
                            <span class="fontz fonts16" style="color: #2f6cbc;">面试</span>
                        </div>
                        <div class="Information_main_time_gray">
                            <span class="fontz">面试时间：{{ personDatas.interviewDate || "暂无" }}</span>
                        </div>
                    </div>
                    <!-- 上传体检报告 -->
                    <div v-if="index == 3">
                        <UploadFileT @uploadImageClick="uploadImageClicks_" style="width: 100%;" />
                    </div>

                    <!-- 背景调查 -->
                    <div v-if="index == 9">
                        <div class="Information_main_time_gray">
                            <span class="fontz fonts16" style="color: #2f6cbc;">背景调查</span>
                        </div>
                    </div>
                    <!-- 录用公示 -->
                    <div v-if="index == 10">
                        <div class="Information_main_time_gray">
                            <span class="fontz fonts16" style="color: #2f6cbc;">录用公示</span>
                        </div>
                    </div>
                    <div v-if="index == 11">
                        <div class="Information_main_time_gray">
                            <span class="fontz fonts16" style="color: #2f6cbc;">待入职</span>
                        </div>
                    </div>

                    <!-- <el-button class="Information_main_blue_btn" type="" plain>HR初筛</el-button>
                    <el-button class="Information_main_blue_btn" type="" plain>笔试</el-button>
                    <el-button class="Information_main_red_btn" type="" plain>HR初筛未通过</el-button>
                    <el-button class="" type="danger">放弃笔试</el-button> -->
                </div>

            </div>
        </div>
    </div>
</template>
  
<script>
import { dictSect, dictFuns } from "@/utils/dictUnit"
import {
    getposition,
    registrations,
    collections,
    editRegistration,
    registrationLog,
} from "@/api/my.js"
export default {
    name: 'Information',
    props: ["data", "indexValue"],
    data() {
        return {
            index: "-1",
            shoucang: false,
            personData: {},
            personDatas: {},
            loading: false,
            status: ""
        }
    },
    watch: {
        data: {
            handler: function (newValue) {
                // console.log("监听", this.indexValue,newValue);
                if (this.indexValue == 0 || this.indexValue == 1) {//首页0、职位招聘1
                    this.status = newValue.status
                    this.personData = newValue
                    this.id = newValue.id
                } else if (this.indexValue == 2) {//已投递,邀请投递，已收藏
                    this.status = newValue.recruitmentPositionVo?.status
                    this.personData = newValue.recruitmentPositionVo
                    this.personDatas = newValue
                    this.id = newValue.positionId
                    this.info(newValue)
                } else if (this.indexValue == 3) {
                    this.status = newValue.recruitmentPositionVo?.status
                    this.personData = newValue.recruitmentPositionVo
                    this.id = newValue.positionId
                    this.personDatas = newValue
                    this.info(newValue)
                }
            },
            immediate: true,
            deep: true
        }
    },
    methods: {
        // classClick(item) {
        //     this.indexValue = item.id
        // },
        toudi() {
            let loginBool = sessionStorage.getItem("loginBool")
            if (loginBool) {
                this.$router.push(`zhiwei_detail?id=${this.id}`)
            } else {
                this.$message({
                    message: `请先登录！`,
                    type: 'error',
                });
            }

        },
        detail() {
            let loginBool = sessionStorage.getItem("loginBool")
            if (loginBool) {
                this.$router.push(`zhiwei_detail?id=${this.id}`)
            } else {
                return
            }
        },
        info(data) {
            this.index = 0 //投递简历
            if (data == null) {
                this.index = 0 //投递简历
            } else {
                if (data.writingTestingStatus == 0) {
                    this.index = 1 //已投递简历
                } else if (data.writingTestingStatus == 1) {
                    this.index = 2 //是否放弃笔试
                } else if (data.writingTestingStatus == "-1") {
                    this.index = 4 //已放弃笔试
                } else if (data.writingTestingStatus == 2) {
                    this.index = 5 //已确定笔试
                    if (data.writingTestingResult == 0) {
                        this.index = 6 //笔试未通过
                    } else if (data.writingTestingResult == 1) {
                        this.index = 7 //笔试通过 开始面试
                    }
                }
                if (data.status == 4) {
                    this.index = 8 //开始面试
                } else if (data.status == 5) {
                    this.index = 9//背景调查
                } else if (data.status == 6) {
                    this.index = 3 //上传体检报告
                } else if (data.status == 7) {
                    this.index = 10//录用公示
                } else if (data.status == 8) {
                    this.index = 11//待入职
                }

            }
        },
        dict(value, res) {
            return dictFuns(value, res)
        },
        string_arrFun(res) {
            // console.log(res);
            let arrs = res ? res.split(",") : []
            return arrs
        },
        collectionApi() {
            let loginBool = sessionStorage.getItem("loginBool")
            if (loginBool) {
                this.$emit("collectionClick", this.id)
            } else {
                this.$message({
                    message: `请先登录！`,
                    type: 'error',
                });
            }

        },
        editRegistrationApi(params) {
            editRegistration(params).then(res => {
                this.$emit("collectionClick", "refush")
                this.$message({
                    message: `${res.msg}`,
                    type: 'success',
                });
            }).catch(res => {
                this.$message({
                    message: `${res.msg}`,
                    type: 'error',
                });
            })
        },
        getup() {
            this.$confirm('确定是否放弃笔试？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    id: this.personDatas.id,
                    writingTestingStatus: "-1"
                }
                this.editRegistrationApi(params)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消操作'
                });
            });

        },
        request() {
            console.log("ths", this.personData);
            let params = {
                id: this.personDatas.id,
                writingTestingStatus: 2
            }
            this.editRegistrationApi(params)
        },
        uploadImageClicks_(value) {
            console.log(value);
            let obj = {
                medicalReportIds: this.personDatas.medicalReportIds,
                id: this.personDatas.id
            }
            obj.medicalReportIds = obj.medicalReportIds ? obj.medicalReportIds + "," + value : value
            console.log(obj);
            this.editRegistrationApi(obj)
        },

    }
}
</script>
  
<style scoped lang="scss">
.Information_main_time_gray {
    margin-top: 16px;
    font-size: 12px;
    color: #898989;
}

.Information_main_time_red {
    margin-top: 16px;
    font-size: 12px;
    color: #FE6470;
}

.Information_main_blue_btn {
    background: #D5E7FF;
    border-radius: 15px 15px 15px 15px;
    opacity: 1;
    border: 1px solid #2F6CBC;
    color: #2F6CBC;
    font-size: 14px;
}

.Information_main_red_btn {
    background: #FDEEF0;
    border-radius: 15px 15px 15px 15px;
    opacity: 1;
    border: 1px solid #FE6470;
    color: #FE6470;
    font-size: 14px;
}

.gray {
    color: #898989;
}

.Information {
    width: 100%;
    background: #F8F9FA;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    border: 1px solid #CACFD6;
    padding: 25px 30px;

    &:hover {
        background: #FFFFFF;
        opacity: 1;
        border: 1px solid #2F6CBC;
    }

    margin-bottom: 14px;

    .Information_main {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .Information_main_title {}

        .Information_main_ {
            display: flex;
            // justify-content: space-between;
            flex-direction: column;

            .Information_main_left_btn {
                margin: 0;
                margin-right: 16px;
                margin-bottom: 16px;
                max-width: 100px;
                padding: 0px 14px;
                line-height: 30px;
                background: #EFF3F7;
                border-radius: 15px 15px 15px 15px;
                opacity: 1;
                font-size: 18px;
                font-weight: 400;
                color: #2F6CBC;
            }
        }

        .Information_main_flex_end {
            align-items: flex-end;
        }
    }

}
</style>
  